{% extends "h:templates/layouts/admin.html.jinja2" %}

{% set page_id = 'features' %}
{% set page_title = 'Feature flags' %}

{% block content %}
  <p>
    This page allows you to configure various feature flags that change the
    behaviour of the application.
  </p>
  <p>
    <strong>N.B.</strong> your changes will take effect immediately when you
    save.
  </p>
  <div class="table-responsive">
    <form method="POST">
      <input
        type="hidden"
        name="csrf_token"
        value="{{ get_csrf_token() }}">
      <table class="table table-striped">
        <thead>
          <tr>
            <th></th>
            <th>Everyone</th>
            <th>Admins</th>
            <th>Staff</th>
            <th>Cohorts</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for feat in features %}
          <tr>
            <td>{{ feat.name }}</td>
            <td>
              <input
                type="checkbox"
                name="{{ feat.name }}[everyone]"
                {% if feat.everyone %}checked{% endif %}>
            </td>
            <td>
              <input
                type="checkbox"
                name="{{ feat.name }}[admins]"
                {% if feat.admins %}checked{% endif %}>
            </td>
            <td>
              <input
                type="checkbox"
                name="{{ feat.name }}[staff]"
                {% if feat.staff %}checked{% endif %}>
            </td>
            <td>
              {% for c in cohorts %}
                <fieldset>
                  <input
                    type="checkbox"
                    id="{{ feat.name }}[cohorts][{{ c.name }}]"
                    name="{{ feat.name }}[cohorts][{{ c.name }}]"
                    {% if c in feat.cohorts %}checked{% endif %}>
                  <label for="{{ feat.name }}[cohorts][{{ c.name }}]">{{ c.name }}</label>
                </fieldset>
              {% endfor %}
            </td>
            <td>
              {{ feat.description }}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      <input class="btn btn-primary" type="submit" value="Save changes">
    </form>
  </div>
{% endblock %}
